﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace StoreWeb.system.order
{
    public partial class detail : System.Web.UI.Page
    {
        Maticsoft.BLL.Orders bll = new Maticsoft.BLL.Orders();
        BLL.member memberbll = new BLL.member();
        Maticsoft.BLL.style stylebll = new Maticsoft.BLL.style();
        Maticsoft.BLL.Ordersize ordersizebll = new Maticsoft.BLL.Ordersize();
        Maticsoft.BLL.Ordertetisize ordertetisizebll = new Maticsoft.BLL.Ordertetisize();
        Maticsoft.BLL.ordervaluetype ordervaluetypebll = new Maticsoft.BLL.ordervaluetype();
        Maticsoft.BLL.OrderPartsStyle orderpartsstylebll = new Maticsoft.BLL.OrderPartsStyle();
        Maticsoft.BLL.Inventory ibll = new Maticsoft.BLL.Inventory();
        protected Maticsoft.Model.Orders order = new Maticsoft.Model.Orders();
        protected Maticsoft.Model.Inventory inventory = new Maticsoft.Model.Inventory();
        protected Model.member member = new Model.member();
        protected string orderview = "";
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                order = bll.GetModel(Convert.ToInt32(Request["id"]));
                if (order != null)
                {
                    inventory = ibll.GetModelList("cinvcode='" + order.cInvCode + "'").First();
                    member = memberbll.GetModel(Convert.ToInt32(order.membercode));//获取客户信息
                    List<Maticsoft.Model.Ordersize> ordersizes = ordersizebll.GetModelList(string.Format("ordercode='{0}'", order.code));//获取订单尺寸
                    List<Maticsoft.Model.Ordertetisize> ordertetisizes = ordertetisizebll.GetModelList(string.Format("ordercode='{0}'", order.code));//获取订单特体尺寸
                    List<Maticsoft.Model.ordervaluetype> ordervalues = ordervaluetypebll.GetModelList(string.Format("ordercode='{0}'", order.code));//获取订单增值信息
                    List<Maticsoft.Model.OrderPartsStyle> orderpartsstyles = orderpartsstylebll.GetModelList(string.Format("ordercode='{0}'", order.code));//获取订单部位款式
                    List<model> list = new List<model>();//合并信息显示
                    List<model> list2 = new List<model>();//套装情况合并信息显示
                    if (ordertetisizes != null)//合并订单特体尺寸
                        foreach (var item in ordertetisizes)
                        {
                            if (item.tzgroup == "1")
                                list.Add(new model() { Text = item.groupname, Value = item.code });
                            else
                                list2.Add(new model() { Text = item.groupname, Value = item.code });
                        }
                    if (ordervalues != null)//合并订单增值信息
                        foreach (var item in ordervalues)
                        {
                            if (item.tzgroup == "1")
                                list.Add(new model() { Text = item.name, Value = item.value });
                            else
                                list2.Add(new model() { Text = item.name, Value = item.value });
                        }
                    if (orderpartsstyles != null)//合并订单部位款式
                        foreach (var item in orderpartsstyles)
                        {
                            if (item.tzgroup == "1")
                                list.Add(new model() { Text = item.partsname, Value = item.cInvName });
                            else
                                list2.Add(new model() { Text = item.partsname, Value = item.cInvName });
                        }

                    List<Maticsoft.Model.Ordersize> lists1 = ordersizes.Where(c => c.tzgroup == "1").ToList();
                    List<Maticsoft.Model.Ordersize> lists2 = ordersizes.Where(c => c.tzgroup == "2").ToList();
                    //生成订单尺寸界面
                    if (lists1 != null)
                    {

                        orderview += "<tr>";
                        orderview += "<td rowspan='" + (lists1.Count + 1) + "'>" + order.cInvCNames.Split(',')[0] + "尺寸</td>";
                        orderview += "<td>部位</td>";
                        orderview += "<td>套码尺寸</td>";
                        orderview += "<td>成衣尺寸</td>";
                        orderview += "<td>建议尺寸</td>";
                        orderview += "<td colspan='3'>款式图片</td>";
                        orderview += "</tr>";
                        for (int i = 0; i < lists1.Count; i++)
                        {
                            orderview += "<tr>";
                            orderview += "<td>" + lists1[i].sizename + "</td>";
                            orderview += "<td>" + lists1[i].backupsize + "</td>";
                            orderview += "<td>" + lists1[i].sizevalue + "</td>";
                            orderview += "<td>" + lists1[i].note + " " + lists1[i].shetnote + "</td>";
                            if (i == 0)
                            {
                                List<Maticsoft.Model.OrderPartsStyle> rps = orderpartsstyles.Where(c => c.tzgroup == "1").ToList();
                                List<Maticsoft.Model.style> styles = stylebll.GetModelList(string.Format("code='{0}'", rps.Count > 0 ? rps.First().stylecode : "0"));
                                Maticsoft.Model.style style = styles != null && styles.Count > 0 ? styles.First() : new Maticsoft.Model.style();
                                orderview += "<td rowspan='" + lists1.Count + "' colspan='4'>" + (!string.IsNullOrEmpty(style.xiaoguourl) ? "<img  style='width:270px;height:270px' src='" + style.xiaoguourl.Split('|')[0] + "'>" : "") + "</td>";//展示款式第一张图
                            }
                            orderview += "</tr>";
                        }
                    }
                    //生成其它属性界面
                    if (list != null)
                    {
                        int sort = 4;
                        for (int i = 0; i < list.Count; i++)
                        {
                            if (sort == 4)
                            {
                                sort = 1;
                                orderview += "<tr>";
                            }
                            else
                                sort++;
                            if (i + 1 == list.Count)//循环到最后一个时判断跨列问题
                                orderview += "<td>" + list[i].Text + "</td><td style='text-align: left; padding-left: 5px;' colspan='" + (sort == 1 ? 7 : (8 - (sort * 2) + 1)) + "'>" + list[i].Value + "</td>";
                            else
                                orderview += "<td>" + list[i].Text + "</td><td style='text-align: left; padding-left: 5px;'>" + list[i].Value + "</td>";
                            if (sort == 4)
                                orderview += "</tr>";
                        }
                    }
                    //生成订单尺寸界面
                    if (lists2 != null && order.istz == "1")
                    {

                        orderview += "<tr>";
                        orderview += "<td rowspan='" + (lists2.Count + 1) + "'>" + order.cInvCNames.Split(',')[1] + "尺寸</td>";
                        orderview += "<td>部位</td>";
                        orderview += "<td>套码尺寸</td>";
                        orderview += "<td>成衣尺寸</td>";
                        orderview += "<td>建议尺寸</td>";
                        orderview += "<td colspan='3'>款式图片</td>";
                        orderview += "</tr>";
                        for (int i = 0; i < lists2.Count; i++)
                        {
                            orderview += "<tr>";
                            orderview += "<td>" + lists2[i].sizename + "</td>";
                            orderview += "<td>" + lists2[i].backupsize + "</td>";
                            orderview += "<td>" + lists2[i].sizevalue + "</td>";
                            orderview += "<td>" + lists2[i].note + " " + lists2[i].shetnote + "</td>";
                            if (i == 0)
                            {

                                List<Maticsoft.Model.OrderPartsStyle> rps = orderpartsstyles.Where(c => c.tzgroup == "2").ToList();
                                List<Maticsoft.Model.style> styles = stylebll.GetModelList(string.Format("code='{0}'", rps.Count > 0 ? rps.First().stylecode : "0"));
                                Maticsoft.Model.style style = styles != null && styles.Count > 0 ? styles.First() : new Maticsoft.Model.style();
                                orderview += "<td rowspan='" + lists2.Count + "' colspan='4'>" + (!string.IsNullOrEmpty(style.xiaoguourl) ? "<img src='" + style.xiaoguourl.Split('|')[0] + "'>" : "") + "</td>";//展示款式第一张图
                            }
                            orderview += "</tr>";
                        }
                    }
                    //生成其它属性界面
                    if (list2 != null && order.istz == "1")
                    {
                        int sort = 4;
                        for (int i = 0; i < list2.Count; i++)
                        {
                            if (sort == 4)
                            {
                                sort = 1;
                                orderview += "<tr>";
                            }
                            else
                                sort++;
                            if (i + 1 == list2.Count)//循环到最后一个时判断跨列问题
                                orderview += "<td>" + list2[i].Text + "</td><td style='text-align: left; padding-left: 5px;' colspan='" + (sort == 1 ? 7 : (8 - (sort * 2) + 1)) + "'>" + list2[i].Value + "</td>";
                            else
                                orderview += "<td>" + list2[i].Text + "</td><td style='text-align: left; padding-left: 5px;'>" + list2[i].Value + "</td>";
                            if (sort == 4)
                                orderview += "</tr>";
                        }
                    }
                    if (!string.IsNullOrEmpty(Request["p"]))//打印
                        Page.ClientScript.RegisterStartupScript(Page.GetType(), "", " <script>doPrint();</script>");
                }
                else
                {
                    Page.ClientScript.RegisterStartupScript(Page.GetType(), "", " <script>alert(\"暂无该订单信息\");</script>");
                }
            }
        }
    }
    class model
    {
        private string _text;

        public string Text
        {
            get { return _text; }
            set { _text = value; }
        }
        private string _value;

        public string Value
        {
            get { return _value; }
            set { _value = value; }
        }
    }
}